/*
 * sensor.h
 *
 *  Created on: 17/11/2012
 *      Author: Richard
 */

#ifndef SENSOR_H_
#define SENSOR_H_

#include "cdef.h"

#define ENTER_CRITICAL()                                       \
   bool boCriticalNesting;                                     \
   boCriticalNesting = ((__get_SR_register() & GIE) == GIE);   \
   __disable_interrupt();

#define EXIT_CRITICAL()                                        \
   if( boCriticalNesting == True )                             \
   {                                                           \
      __enable_interrupt();                                    \
   }

typedef union
{
   uint8 u8AllFlags;
   struct
   {
      uint8 biLowBattery   :1;
      uint8 biSpare        :7;
   } Bits;
} APP_tunFlags;

typedef struct
{
   APP_tunFlags   unFlags;
   tunU16Rec      un16TempOffset;
   tunU32Rec      un32Address;

} APP_tstSystemFlags;

extern volatile APP_tstSystemFlags APP_stSystemFlags;

typedef union
{
   uint8 u8AllRequests;
   struct
   {
      uint8 biTimerEvent            :1;
      uint8 biDebounce              :1;
      uint8 biButtonPress           :1;
      uint8 biProcessSensorPeriod   :1;
      uint8 biSensorReadRequest     :1;
      uint8 biSpare                 :3;
   } F;
} APP_tunRequests;

extern volatile APP_tunRequests APP_unRequests;

#endif /* SENSOR_H_ */
